import { IFeidaoAiBrowserComponent } from '../../interfaces';

/**
 * 显示通知
 * @param title 标题
 * @param msg 消息内容
 * @param action 用户点击消息后的响应(事件)编号
 * @param [image] 通知中图片地址
 * @param [icon] 通知左侧图标地址
 */
export default async function notify(fd: IFeidaoAiBrowserComponent, title: string, msg: string, action: string, icon?: string, image?: string) {
	// Let's check if the browser supports notifications
	if (!('Notification' in window)) {
		console.error('This browser does not support desktop notification');
	} else {
		if (Notification.permission !== 'denied') {
			await Notification.requestPermission();
		}
		if (Notification.permission === 'granted') {
			const n = new Notification(title, {
				body: msg,
				icon,
				image
			});
			n.onclick = (e) => {
				fd.emit(action, e);
			};
		}
	}
}
